package com.wenhai.spring.generic;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashMap;

/**
 * 泛型 API 示例
 *
 * @author wenhai
 * @date   2021/4/9
 */
public class GenericAPIDemo {
    public static void main(String[] args) {
        // primitive type
        Class primitiveClass = int.class;

        // array type
        Class arrayClass = int[].class;

        // raw type 不包含泛型
        Class rawClass = String.class;

        // generic type
        Class genericClass = HashMap.class;
        System.out.println(genericClass);
        Type type = genericClass.getGenericSuperclass();
        System.out.println(type);
        System.out.println(Arrays.toString(genericClass.getGenericInterfaces()));
        System.out.println(Arrays.toString(genericClass.getInterfaces()));
        System.out.println(type.getTypeName());
        System.out.println(Arrays.toString(((ParameterizedType) type).getActualTypeArguments()));
        System.out.println(((ParameterizedType) type).getOwnerType());
        System.out.println(((ParameterizedType) type).getRawType());
    }

}
